var app = getApp()
Page({
  data: {
    statusType: ["全部","待发货", "待收货"],
    currentType: 0,
    tabClass: ["", "", "", "", ""],
    goods_list: null,
  },
  onLoad:function (options){
    //全部
    var that = this;
    that.setData({currentType:options.index})
    var openid = app.globalData.userInfo.open_id;
    wx.request({
      url: app.globalData.apiUrl + '/api/order/order',
      data: { openid: openid, status: null },
      method: 'GET',
      dataType: 'json',
      success: function (res) {
        console.log(JSON.parse(res.data[0].goods_name))
        console.log(res)
        that.setData({ goods_list: res.data })
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  statusTap: function (e) {
    var that = this;
    var curType = e.currentTarget.dataset.index;
    var openid = app.globalData.userInfo.open_id;
    this.data.currentType = curType
    if(curType == 0){
      //全部
      wx.request({
        url: app.globalData.apiUrl+'/api/order/order',
        data: {openid:openid,status:null},
        method: 'GET',
        dataType: 'json',
        success: function(res) {
          console.log(JSON.parse(res.data[0].goods_name))
          that.setData({goods_list:res.data})
        },
        fail: function(res) {},
        complete: function(res) {},
      })

    } else if (curType == 1){

      //待发货
      wx.request({
        url: app.globalData.apiUrl + '/api/order/order',
        data: { openid: openid, status: 0 },
        method: 'GET',
        dataType: 'json',
        success: function (res) {
          console.log(res.data)
          that.setData({ goods_list: res.data })
        },
        fail: function (res) { },
        complete: function (res) { },
      })
    } else if (curType == 2){
      //待收货
      wx.request({
        url: app.globalData.apiUrl + '/api/order/order',
        data: { openid: openid, status: 1 },
        method: 'GET',
        dataType: 'json',
        success: function (res) {
          console.log(res.data)
          that.setData({ goods_list: res.data })
        },
        fail: function (res) { },
        complete: function (res) { },
      }) 
    }
    this.setData({
      currentType: curType
    });
    this.onShow();
  },
  //跳转
  navToInfo:function (tap){
    var id = tap.currentTarget.dataset.id;
    wx.redirectTo({
      url: '/pages/orderInfo/orderInfo?id='+id
    })
  },
  wuliu:function(){
    if(1){
      wx.showToast({
        title: '暂未开放',
        icon:'none'
      })
    }else{
      wx.navigateTo({
        url: '../wuliu/wuliu',
      })
    }
    
  }
})